package com.example.memosystem.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.example.memosystem.R;
import com.example.memosystem.activity.AddActivity;
import com.example.memosystem.activity.ManageActivity;
import com.example.memosystem.bean.Record;

import java.util.List;

public class RecordAdapter extends ArrayAdapter<Record> {

    private List<Record> items;
    public RecordAdapter(Context context, List<Record> items)
    {
        super(context, R.layout.manage_list, items);
        this.items = items;
    }

    @NonNull
    @Override
    public View getView(int position, View convertView, @NonNull ViewGroup parent) {
        if(convertView == null)
        {
            LayoutInflater inflater = LayoutInflater.from(getContext());
            convertView = inflater.inflate(R.layout.manage_list,parent,false);
        }

        TextView title = convertView.findViewById(R.id.manager_list_title);
        TextView con = convertView.findViewById(R.id.manager_list_con);
        TextView time = convertView.findViewById(R.id.manager_list_time);

        Record res = items.get(position);
        title.setText(res.getTitle());
        con.setText(res.getCon());
        time.setText(res.getTim());

        convertView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent1 = new Intent(getContext(), AddActivity.class);
                intent1.putExtra("sta", "1");
                intent1.putExtra("id", res.getId());
                intent1.putExtra("account", res.getU_id());
                intent1.putExtra("title", res.getTitle());
                intent1.putExtra("con", res.getCon());
                intent1.putExtra("time", res.getTim());
                getContext().startActivity(intent1);
            }
        });

        return convertView;
    }

    public RecordAdapter(@NonNull Context context, int resource) {
        super(context, resource);
    }

    public RecordAdapter(@NonNull Context context, int resource, int textViewResourceId) {
        super(context, resource, textViewResourceId);
    }

    public RecordAdapter(@NonNull Context context, int resource, @NonNull Object[] objects) {
        super(context, resource, (Record[]) objects);
    }

    public RecordAdapter(@NonNull Context context, int resource, int textViewResourceId, @NonNull Object[] objects) {
        super(context, resource, textViewResourceId, (Record[]) objects);
    }

    public RecordAdapter(@NonNull Context context, int resource, @NonNull List objects) {
        super(context, resource, objects);
    }

    public RecordAdapter(@NonNull Context context, int resource, int textViewResourceId, @NonNull List objects) {
        super(context, resource, textViewResourceId, objects);
    }
}
